import { Component, OnInit } from '@angular/core';
declare const BMap: any;

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styles: [],
})
export class MapComponent implements OnInit {
  map = new BMap.Map('allmap');
  Police_Icon = new BMap.Icon('./assets/police_icon.png', new BMap.Size(50, 50));
  constructor() {}

  ngOnInit() {
    //  百度地图API功能
    const map = new BMap.Map('allmap');

    // 创建图标
    const CCG_pt = new BMap.Point(116.403035, 39.934217);
    const DYZ_pt = new BMap.Point(116.404224, 39.933722);
    const GXQ_pt = new BMap.Point(116.404712, 39.932764);
    const CCG_Icon = new BMap.Icon('./assets/蔡成功_map.png', new BMap.Size(50, 50));
    const DYZ_Icon = new BMap.Icon('./assets/丁义诊_map.png', new BMap.Size(50, 50));
    const GXQ_Icon = new BMap.Icon('./assets/高小琴_map.png', new BMap.Size(50, 50));
    const CCG_marker = new BMap.Marker(CCG_pt, { icon: CCG_Icon }); // 创建标注
    const DYZ_marker = new BMap.Marker(DYZ_pt, { icon: DYZ_Icon }); // 创建标注
    const GXQ_marker = new BMap.Marker(GXQ_pt, { icon: GXQ_Icon }); // 创建标注
    map.centerAndZoom(CCG_pt, 15);
    setTimeout(() => {
      map.setZoom(14);
    }, 2000); // 2秒后放大到14级
    map.enableScrollWheelZoom(true);

    // const circle = new BMap.Circle(point, 500, { strokeColor: 'blue', strokeWeight: 2, strokeOpacity: 0.5 }); // 创建圆

    // 添加覆盖物
    map.addOverlay(CCG_marker); // 增加蔡成功标点
    map.addOverlay(DYZ_marker); // 增加丁义诊标点
    map.addOverlay(GXQ_marker); // 增加高小琴标点
    // map.addOverlay(circle); // 增加圆
  }

  add_west_police() {
    const police_west_pt = new BMap.Point(116.400495, 39.931927);
    const police_west_marker = new BMap.Marker(police_west_pt, { icon: this.Police_Icon }); // 创建标注
    this.map.addOverlay(police_west_marker);
  }

  add_east_police() {
    const police_east_pt = new BMap.Point(116.405643, 39.932141);
    const police_east_marker = new BMap.Marker(police_east_pt, { icon: this.Police_Icon }); // 创建标注
    this.map.addOverlay(police_east_marker);
  }

  add_south_police() {
    const police_south_pt = new BMap.Point(116.403181, 39.929838);
    const police_south_marker = new BMap.Marker(police_south_pt, { icon: this.Police_Icon }); // 创建标注
    this.map.addOverlay(police_south_marker);
  }

  // 清除覆盖物
  remove_police() {
    this.map.clearOverlays();
  }
}
